package com.gpframework.module.order.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.order.domain.GpOrderFlow;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @ClassName GpOrderFlowReq
 * @Author gpframework
 * @Date 2023-06-16
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpOrderFlowReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("部门ids")
     private String deptIds;
     @ApiModelProperty("订单ID")
     private Long orderId;
     @ApiModelProperty("员工ID")
     private Long userId;
     @ApiModelProperty("员工名称")
     private String nickName;
     @ApiModelProperty("流转节点id")
     private Long configId;
     @ApiModelProperty("流转节点名称")
     private String configName;
     @ApiModelProperty("流入时间")
     private Date inletTime;
     @ApiModelProperty("处理时间")
     private Date processingTime;
     @ApiModelProperty("处理时长")
     private Long processingDuration;
     @ApiModelProperty("超期时长")
     private Long overdueDuration;
     @ApiModelProperty("处理意见")
     private String processingOpinion;
    @ApiModelProperty("联系人及电话")
    private String linkManAndPhone;
    @ApiModelProperty("订单编号")
    private String formCode;
    @ApiModelProperty("客户名称")
    private String clientName;
    @ApiModelProperty("订单状态")
    private String orderStatus;
    @ApiModelProperty("流入时间（开始）")
    private Date inletStartTime;
    @ApiModelProperty("流入时间（结束）")
    private Date inletEndTime;
    @ApiModelProperty("处理时间（开始）")
    private Date processingStartTime;
    @ApiModelProperty("处理时间（结束）")
    private Date processingEndTime;
    @ApiModelProperty("创建人")
    private String createBy;
    @ApiModelProperty("创建开始时间")
    private Date createStartTime;
    @ApiModelProperty("创建结束时间")
    private Date createEndTime;
    @ApiModelProperty("类型")
    private String type;
    @ApiModelProperty("部门id")
    private String deptId;
    @ApiModelProperty("订单状态（颜色）: 1绿 2黄 3红")
    private String status;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpOrderFlow> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (this.getOrderId() != null){
        lqw.eq(alias+"order_id" ,this.getOrderId());
        }
        if (this.getUserId() != null){
        lqw.eq(alias+"user_id" ,this.getUserId());
        }
        if (StringUtils.isNotBlank(this.getNickName())){
            lqw.like("su.nick_name",this.getNickName());
        }
        if (this.getConfigId() != null){
        lqw.eq(alias+"config_id" ,this.getConfigId());
        }
        if (StringUtils.isNotBlank(this.getConfigName())){
            lqw.like(alias+"config_name",this.getConfigName());
        }
        if (this.getInletTime() != null){
        lqw.eq(alias+"inlet_time" ,this.getInletTime());
        }
        if (this.getProcessingTime() != null){
        lqw.eq(alias+"processing_time" ,this.getProcessingTime());
        }
        if (this.getProcessingDuration() != null){
        lqw.eq(alias+"processing_duration" ,this.getProcessingDuration());
        }
        if (this.getOverdueDuration() != null){
        lqw.eq(alias+"overdue_duration" ,this.getOverdueDuration());
        }
        if (StringUtils.isNotBlank(this.getProcessingOpinion())){
        lqw.eq(alias+"processing_opinion" ,this.getProcessingOpinion());
        }
        if (StringUtils.isNotBlank(this.getLinkManAndPhone())){
            lqw.like(alias+"link_man_and_phone" ,this.getLinkManAndPhone());
        }
        if (StringUtils.isNotBlank(this.getFormCode())){
        lqw.eq("o.form_code" ,this.getFormCode());
        }
        if (StringUtils.isNotBlank(this.getClientName())){
        lqw.eq("o.client_name" ,this.getClientName());
        }
        if (StringUtils.isNotBlank(this.getOrderStatus())){
        lqw.eq("o.order_status" ,this.getOrderStatus());
        }
        if (this.getInletStartTime() != null && this.getInletEndTime() != null){
            lqw.between(alias+"inlet_time", this.getInletStartTime(), this.getInletEndTime());
        }
        if (this.getProcessingStartTime() != null && this.getProcessingEndTime() != null){
            lqw.between(alias+"processing_time", this.getProcessingStartTime(), this.getProcessingEndTime());
        }
        if (StringUtils.isNotBlank(this.getCreateBy())){
            lqw.eq(alias+"create_by" ,this.getCreateBy());
        }
        if (this.getCreateStartTime() != null && this.getCreateEndTime() != null){
            lqw.between(alias+"create_time", this.getCreateStartTime(), this.getCreateEndTime());
        }
        if (StringUtils.isNotBlank(this.getType())){
            lqw.apply("find_in_set(gfc.sort,'" + this.getType() + "')");
        }
        if (StringUtils.isNotBlank(this.getDeptId())){
            lqw.apply("find_in_set( " + this.getDeptId() +", gp.dept_ids)");
        }
        if (StringUtils.isNotBlank(this.getStatus())){
            if (StringUtils.equals(this.getStatus(), "1")) {
                lqw.apply("gp.processing_duration BETWEEN gfc.green_min_duration AND gfc.green_max_duration");
            } else if (StringUtils.equals(this.getStatus(), "2")) {
                lqw.apply("gp.processing_duration BETWEEN gfc.yellow_min_duration AND gfc.yellow_max_duration");
            } else {
                lqw.apply("gp.processing_duration > gfc.red_duration");
            }
        }
    }
}
